package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.BaseFile;
import com.briup.jz.service.IFileService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;


@Api(description="日志文件相关接口")
@Validated
@RestController
@RequestMapping("/basefile")
public class FileController {
 @Autowired
    private IFileService basefileService;
  @ApiOperation(value = "通过id查询所有文件日志分类")
    @GetMapping("query")
    public Message query(Long id){
        List<BaseFile> list = basefileService.query(id);
        return MessageUtil.success(list);
    }
  @ApiOperation(value = "通过id删除")
  @GetMapping("deleteById")
  @ApiImplicitParams({
      @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
  })
  public Message deleteById(@NotNull String id){
      basefileService.deleteById(id);
      return MessageUtil.success("删除成功");
  }
  @ApiOperation(value = "保存或更新日志信息")
  @ApiImplicitParams({
          @ApiImplicitParam(name="id",value = "主键",paramType = "query"),
          @ApiImplicitParam(name="fileName",value = "文件名称",paramType = "query",required = true),
          @ApiImplicitParam(name="groupName",value = "组名称",paramType = "query"),
          @ApiImplicitParam(name="uploadTime",value = "上传时间",paramType = "query"),
          @ApiImplicitParam(name="extName",value = "ext时间",paramType = "query"),
          @ApiImplicitParam(name="fileSize",value = "文件大小",paramType = "query"),
          @ApiImplicitParam(name="fileType",value = "文件类型",paramType = "query"),
  })
  @PostMapping("saveOrUpdate")
  public Message saveOrUpdate(BaseFile basefile){
      basefileService.saveOrUpdate(basefile);
      return MessageUtil.success("更新成功");
  }


  
}


//@RestController
//@Validated
//@RequestMapping("/file")
//@Api(description = "文件上传相关接口")
//public class FileController {
//	
//	@Autowired
//    private IFileService basefileService;
//
//    @ApiOperation(value = "分页查询附件信息")
//    @GetMapping("pagequery")
//    @ApiImplicitParams({
//    	@ApiImplicitParam(name="page",value="当前页",paramType="query",required=true),
//    	@ApiImplicitParam(name="pagesize",value = "每页大小",paramType = "query", required=true),
//    	@ApiImplicitParam(name="fileName",value = "文件名称",paramType = "query"),
//    	@ApiImplicitParam(name="datasetId",value = "数据集编号",paramType = "query"),
//    	@ApiImplicitParam(name="uploadDate",value = "上传日期",paramType = "query"),
//    })
//    public Message query(String page){
//        List<BaseFile> list = basefileService.query(page);
//        return MessageUtil.success(list);
//    }
//    
//    @ApiOperation(value = "下载文件")
//    @GetMapping("download")
//    @ApiImplicitParams({
//    	@ApiImplicitParam(name="url",value = "url",paramType = "query"),
//    })
//    public Message query1(String url){
//        List<BaseFile> list = basefileService.query(url);
//        return MessageUtil.success(list);
//    }
//    @ApiOperation(value = "远程文件删除")
//    @GetMapping("deleteById")
//    @ApiImplicitParams({
//        @ApiImplicitParam(name="id",value = "文件id",paramType = "body",required=true),
//    })
//    public Message deleteById(@NotNull String id){
//        basefileService.deleteById(id);
//        return MessageUtil.success("删除成功");
//    }
//
//    @ApiOperation(value = "文件上传", notes="文件大小限制为3M, 上传完成后需要保存图片id与groupid，通过http://121.199.29.84/8888/group1/fileId 来访问图片")
//    @PostMapping("upload")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name="file",value = "file",paramType = "formData"),
//            @ApiImplicitParam(name="fileType",value = "fileType",paramType = "query"),
//    })
//    public Message upload(BaseFile basefile){
//        basefileService.upload(basefile);
//        return MessageUtil.success("更新成功");
//    }
//}

